package com.baohua.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.baohua.dao.BaseDao;
import com.baohua.dao.SupplierDao;
import com.baohua.model.Staff;
import com.baohua.model.Supplier;

/**
 * StaffDao类
 * @author czp
 */

@Repository("supplierDao")
public class SupplierDaoImpl extends BaseDao implements SupplierDao {

	@SuppressWarnings("unchecked")
	public List<Supplier> querySupplier(String sql, int page, int pageSize) {
		Query query = this.getSession().createQuery(sql)
				.setFirstResult(page).setMaxResults(pageSize);
		List<Supplier> list = query.list();
		return list;
	}

	public Supplier querySupplierBySupplierNo(String supplierNO) {
		Supplier supplier = (Supplier)this.getSession().createQuery("from Supplier where supplierNO = ?")
		   .setString(0, supplierNO).uniqueResult();
		return supplier;
	}


	public void delSupplier(Supplier supplier) {
		this.getHibernateTemplate().delete(supplier);
	}

	public void updateSupplier(Supplier supplier) {
		this.getHibernateTemplate().update(supplier);
	}

	public void addSupplier(Supplier supplier) {
		this.getHibernateTemplate().save(supplier);
	}

	@Override
	public long countSupplier(String sql) {
		long count = (Long)this.getSession().createQuery(sql).uniqueResult();
		return count;
	}

	@Override
	public Supplier querySupplierBySupplierId(int supplierId) {
		Supplier supplier = (Supplier)this.getHibernateTemplate().load(Supplier.class, supplierId);
		return supplier;
	}

}
